﻿using System;
using System.Linq;
using System.Windows.Forms;
using StructureMap;
using StructureMap.Interceptors;

namespace ComponentTracer
{
    public class TracingTypeInterceptor : TypeInterceptor
    {
        private readonly Action<string> tracer;

        public TracingTypeInterceptor(Action<string> tracer) {
            this.tracer = tracer;
        }

        public object Process(object target, IContext context) {
            return TracerProxy.Create(target.GetType().GetInterfaces().First(), target, tracer);
        }

        public bool MatchesType(Type type) {
            return !typeof(Control).IsAssignableFrom(type);
        }
    }
}